package be.ac.ua.pats.thesisrobotica.robot.RR.sensors;

//~--- non-JDK imports --------------------------------------------------------

import be.ac.ua.pats.thesisrobotica.robot.RR.Reflective;
import be.ac.ua.pats.thesisrobotica.robot.communication.Connection;
import be.ac.ua.pats.thesisrobotica.robot.constants.RobotConstants;
import be.ac.ua.pats.thesisrobotica.robot.exceptions.InitializationException;
import lejos.nxt.SensorPort;
import lejos.nxt.comm.RConsole;

/**
 * @author Jimmy
 */
public abstract class ColorLightSensor extends Sensor implements Reflective {

    lejos.nxt.ColorLightSensor sensor;

    public ColorLightSensor(SensorPort port) {
        this(null,port);
    }

    public ColorLightSensor(Connection connection,SensorPort port) {
               super(connection);

        sensor      = new lejos.nxt.ColorLightSensor(port, interval);
        type        = RobotConstants.Types.ULTRASONICSENSOR;
        initialized = true;
    }

    /**
     * @return The current sensor reading
     */
    @Override
    public int getRealValue() throws InitializationException {
        if (initialized) {
            return sensor.getLightValue();
        } else {
            throw new InitializationException(this.id);
        }
    }

    @Override
    public String getValue() throws InitializationException {
                if (initialized) {
            return String.valueOf(sensor.getLightValue());
        } else {
            throw new InitializationException(this.id);
        }
    }
}